home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / misc / emu / flamingo.lha / Flamingo / sources / CGX-Refresh.asm < prev    next >
Encoding:
Assembly Source File  |  1999-07-13  |  8.7 KB  |  513 lines

  1. ; CGX-Refresh driver (work on all CGFX 8bit screen)
  2. ; External Video Driver for
  3. ; Flaming Plus/4 emulator for the Amiga
  4. ;
  5. ; version 1.4
  6. ; 1.3: CV64 related modulo fix (18.05.99)
  7. ; 1.4: hi/truecolor screen refresh check (due. promoters) (30.06.99)
  8. ; 1.5: added config support (12.07.99)
  9.  
  10.  
  11. TRUE    equ    1
  12. FALSE    equ    0
  13.         INCDIR    Include3.1:
  14.  
  15.     INCLUDE exec/types.i
  16.     INCLUDE    exec/memory.i
  17.     INCLUDE    exec_lib.i
  18.     INCLUDE    utility/tagitem.i
  19.     INCLUDE    intuition/intuition.i
  20.     INCLUDE    intuition_lib.i
  21.     INCLUDE    intuition/screens.i
  22.     INCLUDE graphics/modeid.i
  23.     INCLUDE    graphics/rastport.i
  24. ;    INCLUDE    macros.i
  25.     INCLUDE    libraries/cybergraphics_lib.i
  26.     INCLUDE    cybergraphics/cybergraphics.i
  27.     include    graphics_lib.i
  28.     INCLUDE    dos_lib.i
  29.     INCLUDE    dos/dostags.i
  30.     INCLUDE    dos/dosextens.i
  31.     INCLUDE    dos/var.i
  32.  
  33. ;*** Handler structure
  34.  
  35.  STRUCTURE vxd_handler,0
  36.   LONG intuibase
  37.   LONG myscr
  38.   LONG mywin
  39.   WORD xsize
  40.   WORD ysize
  41.   LONG palette
  42.   LONG palette32
  43.   LONG emuscr
  44.  
  45.   LONG gfxbase
  46.   LONG cybscrbitmap        ;bitmapstuff
  47.   LONG cybbase
  48.   LONG dosbase
  49.   LONG screendim
  50.  LABEL    vxd_handler_SIZEOF
  51.  
  52.  
  53. JSRLIB    MACRO
  54.     jsr    _LVO\1(a6)
  55.     ENDM
  56.  
  57. ;*** Let's begin
  58.  
  59.     moveq.l    #0,d0
  60.     rts
  61.  
  62.     dc.b "FLAMINGOXVD"
  63.     dc.b "1"
  64.  
  65.     dc.l Name
  66.     dc.l Author
  67.     dc.w 1
  68.     dc.w 5
  69.  
  70.     dc.l drv_Init
  71.     dc.l drv_Done
  72.     dc.l drv_Configure
  73.     dc.l drv_OpenScreen
  74.     dc.l drv_CloseScreen
  75.     dc.l drv_Refresh
  76.  
  77. Name:    dc.b    "CGX-Refresh External Video Driver 1.5 (12.07.99)",0
  78. Author:    dc.b    "László (pH03N1x) Török",0
  79.  
  80.     EVEN
  81.  
  82. ;*** Functions
  83.  
  84. drv_Init:
  85.     movem.l    a0-a1,-(sp)    ;Saving infos
  86.     move.l  4.w,a6        ;Alloc memory for handler
  87.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  88.     move.l    #vxd_handler_SIZEOF,d0
  89.     JSRLIB    AllocVec
  90.     movem.l    (sp)+,a0-a1    ;Recover infos
  91.  
  92.         tst.l    d0
  93.     beq.b    b1        ;No mem
  94.     movea.l    d0,a2
  95.         move.l    8(a0),intuibase(a2)    ;Saving intuition.library base
  96.         move.l    4(a0),dosbase(a2)    ;Saving dos.library base
  97.     move.l    (a0),gfxbase(a2)
  98.  
  99.         movem.l    d0,-(sp)
  100.     move.l    dosbase(a2),a6        ;Reading config file
  101.     move.l    #configfile,d1        ;Config file is pretty simple:
  102.     move.l    #MODE_OLDFILE,d2    ;only a screenmode number
  103.     JSRLIB    Open
  104.     tst.l    d0
  105.     beq.b    .2            ;Failed open
  106.     move.l    d0,d1
  107.     move.l    (sp),a0
  108.     lea    screendim(a0),a0
  109.     move.l    a0,d2
  110.     moveq.l    #4,d3
  111.     movem.l    d0,-(sp)
  112.     JSRLIB    Read            ;Reading the 4 bytes
  113.     cmp.l    #4,d0
  114.     beq.b    .3
  115.     move.l    (sp),a0            ;Failed: set 0 instead garbage
  116.     move.l    #0,screendim(a0)
  117.  
  118. .3    movem.l    (sp)+,d1
  119.     JSRLIB    Close
  120.  
  121. .2    movem.l    (sp)+,d0
  122.  
  123. b1:    move.l    #err_nomem,d1        ;Ignored, if D0 not 0
  124.     rts                ;Result in D0 available for now
  125.  
  126.  
  127.  
  128. drv_Done:
  129.     movea.l    a0,a1
  130.     tst.l    a1
  131.     beq.b    c1
  132.     move.l    4.w,a6    
  133.     JSRLIB    FreeVec        ;Deallocate handler
  134. c1
  135.     rts
  136.  
  137. drv_Configure:            ;Configure
  138.                 ;A simple screenmode requester appears
  139.     movem.l    a0,-(sp)
  140.  
  141.     move.l    a0,a5
  142.     move.l    screendim(a5),ScrDisplayID
  143.  
  144.     moveq    #$00,d0
  145.     moveq    #$00,d1
  146.     move.w    xsize(a5),d0
  147.     move.w    ysize(a5),d1
  148.  
  149.     move.l    d0,cgfxmodewidth
  150.     move.l    d1,cgfxmodeheight
  151.  
  152.     move.l    4.w,a6
  153.     lea    cyblib(pc),a1
  154.     moveq    #40,d0
  155.     jsr    _LVOOpenLibrary(a6)
  156.     move.l    d0,cybbase(a5)
  157.     beq.b    configbug
  158.  
  159.     move.l    cybbase(a5),a6
  160.     lea    cybreqtags(pc),a1
  161.     jsr    _LVOCModeRequestTagList(a6)
  162.  
  163.     cmp.l    #INVALID_ID,d0
  164.     bne.b    config2
  165.  
  166.     move.l    (4).w,a6
  167.     move.l    cybbase(a5),a1
  168.     jsr    _LVOCloseLibrary(a6)
  169.     clr.l    cybbase(a5)
  170.  
  171. configbug:
  172.     suba.l    a0,a0
  173.     move.l    intuibase(a5),a6
  174.     jsr    _LVODisplayBeep(a6)
  175.     move.l    (sp)+,a0
  176.     rts
  177.  
  178. config2:
  179.     move.l    d0,screendim(a5)
  180.     
  181.     move.l    dosbase(a5),a6        ;Writing config file
  182.     move.l    #configfile,d1        ;Config file is pretty simple:
  183.     move.l    #MODE_NEWFILE,d2    ;only a screenmode number
  184.     JSRLIB    Open
  185.     tst.l    d0
  186.     beq.b    .1            ;Failed open
  187.     move.l    d0,d1
  188.     move.l    (sp),a0
  189.     lea    screendim(a0),a0
  190.     move.l    a0,d2
  191.     moveq.l    #4,d3
  192.     movem.l    d0,-(sp)
  193.     JSRLIB    Write            ;Writing the 4 bytes
  194.  
  195.     movem.l    (sp)+,d1        ;We don't care too much on
  196.     JSRLIB    Close            ;success...
  197.  
  198. .1
  199.     move.l    (4).w,a6
  200.     move.l    cybbase(a5),a1
  201.     jsr    _LVOCloseLibrary(a6)
  202.     clr.l    cybbase(a5)
  203.  
  204.     movem.l    (sp)+,a0
  205.     rts
  206.  
  207.  
  208. drv_OpenScreen:
  209.     movea.l a0,a5
  210.  
  211.     move.l    screendim(a0),ScrDisplayID
  212.  
  213.     move.w    (a1)+,xsize(a5)
  214.     move.w    (a1)+,ysize(a5)
  215.     move.l    (a1)+,palette(a5)
  216.  
  217.     move.l    4.w,a6
  218.     lea    cyblib(pc),a1
  219.     moveq    #40,d0
  220.     jsr    _LVOOpenLibrary(a6)
  221.     move.l    d0,cybbase(a5)
  222.     beq.w    e0
  223.  
  224.  
  225.  
  226.     move.w    xsize(a5),cybwidth+2
  227.     move.w    ysize(a5),cybheight+2
  228.  
  229.     tst.l    ScrDisplayID(pc)
  230.     bne    modeisready
  231.  
  232.  
  233.     moveq    #$00,d0
  234.     moveq    #$00,d1
  235.     move.w    xsize(a5),d0
  236.     move.w    ysize(a5),d1
  237.  
  238.     move.l    cybbase(a5),a6
  239.     lea    cybmodetags(pc),a0
  240.     jsr    _LVOBestCModeIDTagList(a6)
  241.     move.l    d0,ScrDisplayID
  242.  
  243.  
  244. modeisready:
  245.  
  246.  
  247.     moveq.l    #0,d0
  248.     move.l    d0,d1
  249.     move.w    xsize(a5),d0
  250.     move.w    ysize(a5),d1
  251.     mulu.w    d1,d0
  252.     move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  253.     move.l    4.w,a6
  254.     JSRLIB    AllocVec
  255.     move.l    d0,emuscr(a5)        ;allocating emulator screen
  256.  
  257.  
  258.     move.l    4.w,a6
  259.     move.l    #MEMF_PUBLIC,d1
  260.     move.l    #128*3*4+8,d0
  261.     JSRLIB    AllocVec
  262.     move.l    d0,palette32(a5)    ;Convert palette to 32 bit per gun
  263.     beq.w    e1
  264.     movea.l    d0,a0
  265.         move.l    palette(a5),a1
  266.     move.w    #128,(a0)+
  267.     move.w    #$0,(a0)+
  268.     move.l    #128*3-1,d2
  269. e2    moveq.l    #0,d0
  270.     move.b    (a1)+,d0
  271.     swap    d0
  272.     asl.l    #8,d0
  273.     move.l    d0,(a0)+
  274.     dbf    d2,e2
  275.     move.l    #0,(a0)
  276.     move.w    xsize(a5),width+2
  277.     move.w    ysize(a5),height+2
  278.     move.l    palette32(a5),pal
  279.  
  280.         suba.l    a0,a0            ;No newscreen stuct
  281.         lea    scrtags,a1
  282.     movea.l    intuibase(a5),a6
  283.     JSRLIB    OpenScreenTagList
  284.  
  285.     move.l    d0,wscr
  286.     move.l    d0,myscr(a5)
  287.     beq.b    e1
  288.  
  289.  
  290.     move.l    d0,a1
  291.     lea    sc_RastPort(a1),a1
  292.     move.l    rp_BitMap(a1),a0
  293.     move.l    a0,cybscrbitmap(a5)
  294.  
  295.     movea.l    intuibase(a5),a6
  296.     move.w    xsize(a5),wwidth+2
  297.     move.w    ysize(a5),wheight+2
  298.     suba.l    a0,a0
  299.     lea    wintags,a1
  300.     JSRLIB    OpenWindowTagList
  301.     move.l    d0,mywin(a5)
  302.     beq.b    e1
  303.     movea.l    d0,a1
  304.  
  305.     move.l  wd_UserPort(a1),d0    ;IDCMP port
  306.     move.l    emuscr(a5),d2        ;chunky buffer
  307.     moveq    #$00,d3            ;no modulo
  308.  
  309. e0:    move.l    #err_cyblib,d1
  310.     rts
  311.  
  312.  
  313. e1    move.l    #err_noscr,d1
  314.     rts
  315.  
  316. drv_CloseScreen:
  317.  
  318.     move.l    a0,a5
  319.     
  320.     tst.l    cybbase(a5)
  321.     beq.b    nemcyb
  322.     move.l    (4).w,a6
  323.     move.l    cybbase(a5),a1
  324.     jsr    _LVOCloseLibrary(a6)
  325.     clr.l    cybbase(a5)
  326.  
  327. nemcyb:    move.l    intuibase(a5),a6
  328.     move.l    mywin(a5),a0
  329.     tst.l    a0
  330.     beq.b    f1
  331.     JSRLIB    CloseWindow
  332.  
  333. f1    move.l    myscr(a5),a0
  334.     tst.l    a0
  335.     beq.b    f2
  336.     JSRLIB    CloseScreen
  337.  
  338. f2    movea.l    palette32(a5),a1
  339.         tst.l    a1
  340.     beq.b    f3
  341.     move.l    4.w,a6
  342.     JSRLIB    FreeVec        ;Deallocate translated palette
  343.  
  344.  
  345. f3    movea.l    emuscr(a5),a1
  346.         tst.l    a1
  347.     beq.b    f4
  348.     move.l    4.w,a6
  349.     JSRLIB    FreeVec        ;Deallocate translated palette
  350.  
  351.  
  352. f4:    move.l    d0,emuscr(a5)    ;They were already freed
  353.     move.l    d0,palette32(a5)
  354.     move.l    d0,myscr(a5)
  355.     move.l    d0,mywin(a5)
  356.  
  357.     rts
  358.  
  359. drv_Refresh:
  360.  
  361.     move.l    emuscr(a0),d7
  362.  
  363.     move.l    d7,a4
  364.     move.l    a4,a5
  365.  
  366.     moveq    #$00,d5
  367.     move.w    xsize(a0),d5
  368.     move.l    d5,d3
  369.  
  370.     moveq    #$00,d6
  371.     move.w    ysize(a0),d6
  372.     subq.l    #1,d6
  373.  
  374.     move.l    cybbase(a0),a6
  375.     move.l    cybscrbitmap(a0),a0
  376.     lea    cgfxlocktags(pc),a1
  377.     jsr    _LVOLockBitMapTagList(a6)    ;d0 = lock
  378.  
  379.     cmp.l    #1,bytesperpix
  380.     bne.b    norefresh            ;nem 8 bites a screen, szoval nincs refresh
  381.  
  382.     move.l    GfxBoardBitmapWidth(pc),d4    ;modulo (CV64 miatt ez az egyeduli korrekt mod)
  383.  
  384.     asr.l    #2,d5            ;/4 (long copy)
  385.     subq.l    #1,d5
  386.  
  387.     move.l    gfxboarddirectmem(pc),a3    ;a3 dest address
  388.     move.l    a3,a2
  389.  
  390. yloop:    move.l    d5,d2
  391. xloop:    move.l    (a4)+,(a3)+
  392.     dbf    d2,xloop
  393.  
  394.     add.l    d3,a5
  395.     move.l    a5,a4                ;next line (source)
  396.  
  397.     add.l    d4,a2
  398.     move.l    a2,a3                ;next line (dest)
  399.  
  400.     dbf    d6,yloop
  401.  
  402. norefresh:
  403.     move.l    d0,a0                ;bitlock
  404.  
  405.     jsr    _LVOUnLockBitMap(a6)
  406.  
  407.     move.l    d7,d0
  408.         RTS
  409.  
  410. ;*** Constants
  411.  
  412.  
  413. cyblib:        dc.b    "cybergraphics.library",0
  414.  
  415.  
  416. scrtags:
  417.     dc.l    SA_Width
  418. width:    dc.l    0
  419.     dc.l    SA_Height
  420. height:    dc.l    0
  421.     dc.l    SA_Depth,8
  422.     dc.l    SA_Colors32
  423. pal:    dc.l    0
  424.     dc.l    SA_Title,scrtitle
  425.     dc.l    SA_ShowTitle,FALSE
  426.     dc.l    SA_DisplayID
  427.  
  428. ScrDisplayID:
  429.     dc.l    0
  430.  
  431.     dc.l    SA_Type,CUSTOMSCREEN
  432.     dc.l    SA_AutoScroll,TRUE
  433.     dc.l    SA_Overscan,OSCAN_STANDARD
  434.     dc.l    SA_Quiet,TRUE
  435.     dc.l    TAG_DONE
  436.  
  437. wintags:
  438.     dc.l    WA_Left,0
  439.     dc.l    WA_Top,0
  440.     dc.l    WA_Width
  441. wwidth:    dc.l    0
  442.     dc.l    WA_Height
  443. wheight:    dc.l    0
  444.     dc.l    WA_IDCMP,IDCMP_RAWKEY
  445.     dc.l    WA_Title,0
  446.     dc.l    WA_Backdrop,TRUE
  447.     dc.l    WA_RMBTrap,TRUE
  448.     dc.l    WA_Borderless,TRUE
  449.     dc.l    WA_NoCareRefresh,TRUE
  450.     dc.l    WA_CustomScreen
  451. wscr:    dc.l    0
  452.     dc.l    WA_SimpleRefresh,TRUE
  453.     dc.l    WA_Activate,TRUE
  454.     dc.l    TAG_DONE
  455.  
  456. scrtitle:    dc.b    'Flamingo Plus/4 emulator screen',0
  457.         EVEN
  458.  
  459. configfile:    dc.b    'cgfx-refresh.cfg',0
  460.         EVEN
  461.  
  462. cybmodetags:
  463.         dc.l    CYBRBIDTG_Depth,8
  464.         dc.l    CYBRBIDTG_NominalWidth
  465. cybwidth:    dc.l    0        
  466.         dc.l    CYBRBIDTG_NominalHeight
  467. cybheight:    dc.l    0
  468.         dc.l    TAG_END
  469.  
  470. cgfxlocktags:    dc.l    LBMI_BASEADDRESS
  471.         dc.l    gfxboarddirectmem
  472.         dc.l    LBMI_BYTESPERROW
  473.         dc.l    GfxBoardBitmapWidth    
  474.         dc.l    LBMI_BYTESPERPIX
  475.         dc.l    bytesperpix            ;egy kis check a kreativ userek (promoter) miatt
  476.  
  477.         dc.l    TAG_END
  478.  
  479. gfxboarddirectmem:
  480.         dc.l    0
  481. GfxBoardBitmapWidth:
  482.         dc.l    0
  483. bytesperpix:    dc.l    0        
  484.  
  485.  
  486. cybreqtags:    
  487.         dc.l    CYBRMREQ_MinWidth
  488. cgfxmodewidth:    dc.l    0        
  489.         dc.l    CYBRMREQ_MinHeight
  490. cgfxmodeheight:    dc.l    0
  491.         dc.l    CYBRMREQ_MinDepth
  492. cgfxmodedepth:    dc.l    8
  493.         dc.l    CYBRMREQ_MaxDepth
  494. cgfxmaxdepth:    dc.l    8
  495.         dc.l    CYBRMREQ_CModelArray
  496. cgfxpixform:    dc.l    cybreqcolors256
  497.         dc.l    TAG_END
  498.  
  499. cybreqcolors256:
  500.         dc.l    PIXFMT_LUT8
  501.         dc.l    TAG_END
  502.  
  503.  
  504. ;*** Errors
  505.  
  506. err_nomem:
  507.     dc.b    'Run out of memory',0
  508. err_noscr:
  509.     dc.b    'Cannot open screen',0
  510. err_cyblib:
  511.     dc.b    'Cannot open cybergraphics.library v40+',0
  512.  
  513.